﻿using UnityEngine;
using System.Collections;

public class HealthScript : MonoBehaviour
{
	public int hp = 1;
	public bool isEnemy = true;
	
	public void Damage(int damageCount)
	{
		hp -= damageCount;
		
		if(hp <= 0)
		{
			Destroy(gameObject);
		}
	}
	
	void OnTriggerEnter2D(Collider2D other)
	{
		ShotScript shot = other.gameObject.GetComponent<ShotScript>();
		
		if(shot != null)
		{
			if(shot.isEnemyShot != isEnemy)
			{
				Damage(shot.damage);
				
				Destroy(shot.gameObject);
			}
		}
	}

	public int GetHealth()
	{
		return hp;
	}
}
